package phone;

import pub.ConfigFile;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.util.Log;

public class Run3gp {
	Service service;
	Context context;
	Intent it ;
	/*public Run3gp(Service service){
		this.service=service;
		it = new Intent(service,Play3gpFile.class);
	}*/
	
	private static Play3gpFile play3gpFile;
	private ServiceConnection serviceConnection = new ServiceConnection() {
		public void onServiceConnected(ComponentName name,IBinder service) {
			// TODO Auto-generated method stub
			play3gpFile = ((Play3gpFile.MyBinder) (service)).getService();
			if (play3gpFile!=null) {
				play3gpFile.toRun();
			}
			System.out.println("bind.......");
		}

		public void onServiceDisconnected(ComponentName name) {
			System.out.println("unbind.......");
		}
	};

	
	public Run3gp(Context context){
		this.context=context;
		it = new Intent(context,Play3gpFile.class);
	}
	public void start(int type,String fileName){
		
		Bundle bundle = new Bundle();
		bundle.putInt("BundleType",Play3gpFile.CommandStart);
		bundle.putInt("PlayType",type);
		if (type==Play3gpFile.TypeFile) {
			//String FilePath=Environment.getExternalStorageDirectory().getPath();
			//String apkPathName=FilePath + "/" + fileName;
			bundle.putString("FilePathName", fileName);
			//context.startService(it);
		} else {
			bundle.putString("FilePathName", "");
			//context.bindService(it,serviceConnection, Context.BIND_AUTO_CREATE); 
		}
		it.putExtras(bundle);
		//service.startService(it);
		//
		context.bindService(it,serviceConnection, Context.BIND_AUTO_CREATE);
	}
	
	public void stop(int type) {
		/*if (type==Play3gpFile.TypeFile) {
		//service.stopService(it);
			context.stopService(it);
		} else {
			context.unbindService(serviceConnection);
		}*/
		System.out.println("run3gp stop.......");
		if (ConfigFile.isRun3GPFile!=0) {
			System.out.println("in stop.......");
			context.unbindService(serviceConnection);
		}
		//context.stopService(it);
		
	}
}
